const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    z1:cc.Node = null;

    @property(cc.Node)
    z2:cc.Node = null;

    @property(cc.Node)
    y1:cc.Node = null;

    @property(cc.Node)
    y2:cc.Node = null;

    @property({type: cc.AudioClip })
    audio:cc.AudioClip = null;
    
    // LIFE-CYCLE CALLBACKS:
    private loaction:any;
    onLoad () {
        this.node["bomb"]=this;
      this.loaction={z1:new cc.Vec2(this.z1.x,this.z1.y),z2:new cc.Vec2(this.z2.x,this.z2.y),y1:new cc.Vec2(this.y1.x,this.y1.y),y2:new cc.Vec2(this.y2.x,this.y2.y)}
    }
    private runBo=false;
    start () {
       
    }
    private tlObj:any;
    private xObj:any;
    private souID:number;
    public Init(){
        for(let s in this.loaction){
            this[s].x=this.loaction[s].x;
            this[s].y=this.loaction[s].y;
        }
        let tl=10;
        let xl=25;
        this.tlObj={z1:tl+3,z2:tl,y1:tl+3,y2:tl}
        this.xObj={z1:0,z2:0,y1:0,y2:0}
        this.num=50;
        this.runBo=true;
        this.souID=cc.audioEngine.play(this.audio, false, 0.7);
    }
    onDestroy() {
        cc.audioEngine.stop(this.souID);
    }
    private num=0;
    update (dt) {
        if(this.runBo){
            
            for(let s in this.loaction){
                this[s].y+=this.tlObj[s];
                this.tlObj[s]-=1;
                if(this.tlObj['z2']<0){
                    if(s=="z1"||s=="z2"){
                        this[s].x-=this.xObj[s];
                        this.xObj[s]+=0.25;
                    }else{
                        this[s].x+=this.xObj[s];
                        this.xObj[s]+=0.2;
                    }
                }
            }
            this.num--;
            if(this.num<=0){
                for(let s in this.loaction){
                    this[s].x=this.loaction[s].x;
                    this[s].y=this.loaction[s].y;
                } 
                this.runBo=false;
                this.node.parent=null;
                window["pool"]["addPrefab"]("polie",this.node);
            }
        }
    }
}
